<template>
  <el-dialog :title="title" custom-class="person-dialog" :close-on-click-modal="false" :modal="false"
    :visible.sync="open" :before-close="handleClose">
    <!-- 查询条件 -->
    <el-form ref="queryForm" :model="query" size='small' class="query-form" inline>
      <el-form-item label="姓名" prop="personName">
        <el-input v-model="query.personName" placeholder="请输入姓名" @keyup.enter.native='getList'></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="personTel">
        <el-input v-model="query.personTel" placeholder="请输入电话" @keyup.enter.native='getList'></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size='mini' @click="handleReset">重置</el-button>
        <el-button size='mini' @click="getList">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格数据 -->
    <el-table :data="tableData" cell-class-name="table-cell-custom" header-cell-class-name="table-herder-custom"
      highlight-current-row @selection-change='selectionChange' @row-dblclick='rowDblclick' height="calc(100% - 72px)"
      size="small">
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column label="姓名" prop="personName"> </el-table-column>
      <el-table-column label="职务" prop="dutyName"> </el-table-column>
      <el-table-column label="部门" prop="groupName"> </el-table-column>
      <el-table-column label="电话" prop="personTel"> </el-table-column>
      <!-- <el-table-column label="年龄" prop="age" align="center">
      </el-table-column> -->
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="query.current" :limit.sync="query.size" align='left'
      @pagination="getList" />
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCommit()" size="small">确 定</el-button>
      <el-button @click="handleClose" size="small">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { personPage } from '@/api/supplies'
import Pagination from '@/components/Pagination'

export default {
  props: {
    open: Boolean,
  },
  components: {
    Pagination,
  },
  data() {
    return {
      title: '人员选择',
      total: 0, // 条数
      query: { current: 1, size: 20, personName: '', personTel: '' },
      tableData: [],
      selectedRows: [],
    }
  },
  methods: {
    // 双击
    rowDblclick(row) {
      this.selectedRows = [row]
      this.handleCommit()
    },
    // 选择
    selectionChange(rows) {
      this.selectedRows = rows
    },
    // 重置查询
    handleReset() {
      this.$refs.queryForm.resetFields()
      this.getList()
    },
    // 确定
    handleCommit() {
      this.handleClose()
      this.$emit('commit', this.selectedRows)
    },
    // 关闭或取消
    handleClose() {
      console.log('handleClose')
      this.$emit('update:open', false)
    },
    // 获取列表
    getList() {
      personPage(this.query).then((res) => {
        this.tableData = res.records
        this.total = res.total
      })
    },
  },
  mounted() {
    this.getList()
  },
}
</script>

<style lang="scss" scoped>
@import '~@/assets/scss/person_dialog.scss';
</style>
